﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MarginTrading.Entity;
using MarginTrading.Common;
using MarginTrading.Services;

namespace MarginTrading.Forms
{
    public partial class EditHoliday : Form
    {
        DateTime day = DateTime.MinValue;
        string sDescription = "";

        public EditHoliday(DateTime day, string description)
        {
            InitializeComponent();

            this.day = day;
            sDescription = description;
        }

        private void EditHoliday_Load(object sender, EventArgs e)
        {
            textBoxDate.Text = day.ToLongDateString();
            textBoxDescription.Text = sDescription;
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (textBoxDescription.Text == "")
            {
                MessageBox.Show("Enter holiday description", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Holiday holiday = new Holiday();
            holiday.day = day;
            holiday.description = textBoxDescription.Text;

            try
            {
                HolidayServices.Update(holiday);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Failed to edit holiday information", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show("Holiday updated successfully");
            Close();
        }
    }
}
